﻿using Deliveryroomstatusbulletin.EntityData;
using DeliveryRoomStatusManage.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Collections.ObjectModel;
using System.Xml;
using System.Configuration;
using Skynet.ConfigurationManagement;
using Deliveryroomstatusbulletin.BusinessRules;
using SystemFramework.NewCommon;
using System.IO;

namespace DeliveryRoomStatusManage
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            //tbHosName.Text = Settings.Default.HospitalName;
            //listboxdata.ItemsSource = budData();
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            List<Item> list = new List<Item>();
            DeliveryroomstatusbulletinRules deliRule = new DeliveryroomstatusbulletinRules();
            EntityList<DeliveryroomstatusbulletinData> listDeliData = deliRule.GetWaits();
            for (int i = 0; i < listDeliData.Count; i++)
            {
                DeliveryroomstatusbulletinData puerpera;
                puerpera = new DeliveryroomstatusbulletinData();
                puerpera.Inhosid = listDeliData[i].Inhosid;
                puerpera.Bedid = listDeliData[i].Bedid;
                puerpera.Childbirthstate = listDeliData[i].Childbirthstate;
                puerpera.Name = listDeliData[i].Name;
                puerpera.Goods = listDeliData[i].Goods;
                puerpera.STATEcaption1 = listDeliData[i].STATEcaption1;
                puerpera.STATEcaption2 = listDeliData[i].STATEcaption2;
                puerpera.STATEcaption3 = listDeliData[i].STATEcaption3;
                Item item = new Item(puerpera);
                list.Add(item);
            }
            listboxdata.ItemsSource = list;

            for (int i = 1; i < 8; i++) 
            {
                BindDocData(i);
            }
        }

        private void tb_Name7_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            tb_Name7.Visibility = Visibility.Collapsed;
            edit_Name7.Visibility = Visibility.Visible;
            edit_Name7.Text = tb_Name7.Text;
        }

        private void tb_Name6_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            tb_Name6.Visibility = Visibility.Collapsed;
            edit_Name6.Visibility = Visibility.Visible;
            edit_Name6.Text = tb_Name6.Text;
        }

        private void edit_Name7_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                Settings.Default.麻醉师 = edit_Name7.Text;
                Settings.Default.Save();
                BindDocData(7);
                tb_Name7.Visibility = Visibility.Visible;
                edit_Name7.Visibility = Visibility.Collapsed;
            }
        }

        private void edit_Name6_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                Settings.Default.儿科医生 = edit_Name6.Text;
                Settings.Default.Save();
                BindDocData(6);
                tb_Name6.Visibility = Visibility.Visible;
                edit_Name6.Visibility = Visibility.Collapsed;
            }
        }


        private void tb_Name5_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            tb_Name5.Visibility = Visibility.Collapsed;
            edit_Name5.Visibility = Visibility.Visible;
            edit_Name5.Text = tb_Name5.Text;
        }
        private void edit_Name5_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                Settings.Default.当班医生 = edit_Name5.Text;
                Settings.Default.Save();
                BindDocData(5);
                tb_Name5.Visibility = Visibility.Visible;
                edit_Name5.Visibility = Visibility.Collapsed;
            }
        }

        private void tb_Name4_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            tb_Name4.Visibility = Visibility.Collapsed;
            edit_Name4.Visibility = Visibility.Visible;
            edit_Name4.Text = tb_Name4.Text;
        }

        private void edit_Name4_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                Settings.Default.助产士 = edit_Name4.Text;
                Settings.Default.Save();
                BindDocData(4);
                tb_Name4.Visibility = Visibility.Visible;
                edit_Name4.Visibility = Visibility.Collapsed;
            }
        }

        private void tb_Name3_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            tb_Name3.Visibility = Visibility.Collapsed;
            edit_Name3.Visibility = Visibility.Visible;
            edit_Name3.Text = tb_Name3.Text;
        }

        private void edit_Name3_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                Settings.Default.待产组长 = edit_Name3.Text;
                Settings.Default.Save();
                BindDocData(3);
                tb_Name3.Visibility = Visibility.Visible;
                edit_Name3.Visibility = Visibility.Collapsed;
            }
        }

        private void tb_Name2_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            tb_Name2.Visibility = Visibility.Collapsed;
            edit_Name2.Visibility = Visibility.Visible;
            edit_Name2.Text = tb_Name2.Text;
        }

        private void edit_Name2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                Settings.Default.护士长 = edit_Name2.Text;
                Settings.Default.Save();
                BindDocData(2);
                tb_Name2.Visibility = Visibility.Visible;
                edit_Name2.Visibility = Visibility.Collapsed;
            }
        }

        private void tb_Name1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            tb_Name1.Visibility = Visibility.Collapsed;
            edit_Name1.Visibility = Visibility.Visible;
            edit_Name1.Text = tb_Name1.Text;
        }

        private void edit_Name1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                Settings.Default.产房负责人=edit_Name1.Text;
                Settings.Default.Save();
                BindDocData(1);
                tb_Name1.Visibility = Visibility.Visible;
                edit_Name1.Visibility = Visibility.Collapsed;
            }
        }

        //绑定姓名及照片
        private void BindDocData(int i) 
        {
            switch (i) 
            {
                case 1:
                    tb_Name1.Text = Settings.Default.产房负责人;
                    break;
                case 2:
                    tb_Name2.Text = Settings.Default.护士长;
                    break;
                case 3:
                    tb_Name3.Text = Settings.Default.待产组长;
                    break;
                case 4:
                    tb_Name4.Text = Settings.Default.助产士;
                    break;
                case 5:
                    tb_Name5.Text = Settings.Default.当班医生;
                    break;
                case 6:
                    tb_Name6.Text = Settings.Default.儿科医生;
                    break;
                case 7:
                    tb_Name7.Text = Settings.Default.麻醉师;
                    break;
                default:
                    break;
            }
            string strTbName = "tb_Name"+i.ToString();
            string strImageName = "image_"+i.ToString();
            try
            {
                TextBlock tb = this.TryFindResource(strTbName) as TextBlock;
                Image image = this.TryFindResource(strImageName) as Image;
                BitmapImage bitImage = new BitmapImage(new Uri("Image/" + tb.Text + ".jpg", UriKind.Relative));
                image.Source = bitImage;
            }
            catch (Exception)
            {
            }
           

        }

      

    }
}
